﻿using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Drawing;
using System.Linq;
using System.Text;
 
using System.Windows.Forms;
using ZXing.Common;
using ZXing.QrCode;
using ZXing;
using GK.WCS.Open; 

namespace Print.printServer {
    public class Code128Printer {
        int d = 0;
        public void print(int Code) {
            d = Code;
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(printEventHandler);

            pd.DefaultPageSettings.PrinterSettings.PrinterName = GKtsc.PrinterName;       //打印机名称
                                                                                                     //pd.DefaultPageSettings.Landscape = true;  //设置横向打印，不设置默认是纵向的
            pd.PrintController = new StandardPrintController();
            pd.Print();
        }

        private void printEventHandler(object sender, PrintPageEventArgs e) { 
            try { 
                int x = -10; 
                e.Graphics.DrawImage(getbmp(d+""),x, 10);
               // e.Graphics.DrawString(d + "", fntTxt, brush, new Point(60, 90));
            } catch (Exception ee) {
                MessageBox.Show(ee.Message);
            }
        }



        private Bitmap getbmp(String code) {
            //设置条码的规格
            EncodingOptions encoding = new QrCodeEncodingOptions {
             
                Width = 200,
                Margin = 0,
                Height = 100
            }; 
            //生成条码的图片并保存
            BarcodeWriter bw = new BarcodeWriter();
            //指定规格
            bw.Options = encoding;
            bw.Format = BarcodeFormat.CODE_128;
            
            Bitmap btp = bw.Write(code);
            return btp;
          
        }


      
    }
}
